import Taro from "@tarojs/taro";
import getBaseUrl from "./baseUrl";

export async function uploadFile(url) {
  const base = getBaseUrl();
  return Taro.uploadFile({
    url: `${base}/files/attachments`,
    name: "files",
    filePath: url,
    formData: {
      ocr: "async",
    },
    header: {
      "Content-Type": "multipart/form-data",
    },
  }).then((r) => {
    const data = JSON.parse(r.data || "[]")[0];
    return { ...data };
  });
}

export const formObejct = (values) => {
  let newData = {};
  for (let key in values) {
    if (values[key]) {
      newData[key] = values[key];
    }
  }
  return newData;
};

export const diseaseAge = [
  { code: "B35", name: "35岁前" },
  { code: "R35-50", name: "35-50岁之间" },
  { code: "A50", name: "50岁以后" },
];

export const smokingNumDayData = [
  { code: "A", name: "<10支" },
  { code: "B", name: "10-20支" },
  { code: "C", name: ">=20支" },
];
export const smokingYearsData = [
  { code: "A", name: "<5年" },
  { code: "B", name: "5-10年" },
  { code: "C", name: "10-20年" },
  { code: "D", name: "20年及以上" },
];

export const drugsUseTimeData = [
  { code: "A", name: "半年内" },
  { code: "B", name: "半年-2年" },
  { code: "C", name: "2年以上" },
];

export const drugsUseTimeDataB = [
  { code: "A", name: "半年内" },
  { code: "B", name: "半年-2年" },
  { code: "C", name: "2年以上" },
  { code: "D", name: "不详" },
];

export const heightReg = /^(1\d{2}|2\d{2}|300)$/;

export const weightReg = /^\d{2,3}$/;
export const menarcheReg = /^(20|1[0-9]|[5-9])$/;
export const pregnancyNumReg = /^(50|4[0-9]|3[0-9]|2[0-9]|1[0-9]|[0-9])$/;
export const birthNumReg = /^(50|4[0-9]|3[0-9]|2[0-9]|1[0-9]|[1-9])$/;
export const childbearingNumReg =
  /^(5[0-5]|4[0-9]|3[0-9]|2[0-9]|1[0-9]|[8-9])$/;
export const durationOfSleepReg = /^(2[0-4]|1[0-9]|[1-9])$/;
export const amenorrheaAgeReg = /^(6[0-9]|5[0-9]|4[0-9]|3[0-9])$/;
